package com.intel.factorytest.util;

import java.io.File;

import android.content.Context;
import android.os.Environment;

public class SDCardUtil {
    // storageList = [/storage/emulated/0, /storage/sdcard1, /storage/usbcard1] sdcard_ext
    public static final String EXTERNAL_STORAGE_PATH = "/storage/sdcard1";
    public static final String INTERNAL_STORAGE_PATH = "/storage/emulated/0";
    
    
    public static String getSDPath() {
        String externalPath = null;
        boolean sdCardExist = Environment.getExternalStorageState().equals(
                android.os.Environment.MEDIA_MOUNTED); // 判断sd卡是否存在
        if (sdCardExist) {
            externalPath = Environment.getExternalStorageDirectory()
                    .getAbsolutePath();// 获取跟目录
        }
        return externalPath;

    } 
    
    /**
     * 获取所有存储卡路径
     * 
     * @param ctx
     * @return
     */
    public static String[] getStorageList(Context ctx) {
        return StorageList.getInstance(ctx).getVolumnPaths();
    }
    
    public static String getExternalStoragePath() {
        String path = null;
        File extStorage = new File(EXTERNAL_STORAGE_PATH);
        String[] files = extStorage.list();
        if (files == null || files.length == 0) {
            path = INTERNAL_STORAGE_PATH;
        } else {
            path = EXTERNAL_STORAGE_PATH;
        }
        return path;
    }
    
//    /**
//     * return external storage path if external storage already mounted, otherwise return internal storage path 
//     * @return
//     */
//    public static String getExternalStoragePath() {
//        if (getSpecialStorageState(new File(EXTERNAL_STORAGE_PATH))) {
//            return EXTERNAL_STORAGE_PATH;
//        } else {
//            return INTERNAL_STORAGE_PATH;
//        }
//    }
//
//    private static boolean getSpecialStorageState(File file) {
//        return Environment.getStorageState(file).equals(android.os.Environment.MEDIA_MOUNTED); // 判断指定的sd卡是否存在
//    }
//    
//    public static String getExternalStoragePath1() {
//        return null;
//    }
}
